#include <iostream>
#include <sstream>
#include <string>
using namespace std;

class Dog
{
private:
	int age;
	string name;
public:
	Dog(int age, string name)
	{
		this->age = age;
		this->name = name;
	}
	int get_age()
	{
		return this->age;
	}

	string get_name()
	{
		return this->name;
	}
};

//new 和 delete 也不是函数，它们都是 C++ 定义的关键字
void test_new_delete()
{
	//数组类型
	string *psa = new string[10];
	//释放内存
	delete[] psa;


	//二维数组(3行5列)
	string **arr = new string*[3];

	for (int i = 0; i < 3; i++)
	{
		arr[i] = new string[5];
		for (int j = 0; j < 5; j++)
		{
			//拼接字符串
			ostringstream oss;
			oss << i<< "_" << j << "";
			arr[i][j] = oss.str();
		}
	}

	for (int i = 0; i < 3; i++)
	{
		for (int j = 0; j < 5; j++)
		{
			cout << arr[i][j]<<"\t";
		}
		cout << "\n";
	}
	//释放内存
	for (int i = 0; i < 3; i++)
	{
		delete[]arr[i];
	}

	delete[]arr;

	//普通类型
	int *pa = new int(34);
	cout << *pa << endl;
	delete(pa);

	//对象类型
	Dog * p_dog = new Dog(2,"旺财");
	cout << p_dog->get_age() << endl;

	cout << p_dog->get_name() << endl;

	delete(p_dog);

}